package com.wasu.service;

import java.util.List;

import org.joda.time.LocalDate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wasu.bean.AdSchedule;

@Controller
@RequestMapping("/order")
public class OrderReSync  {

	@ResponseBody
	@RequestMapping("/orderresync")
	public int orderresync(@RequestParam("adcode") String adcode,@RequestParam("type")String type){
		
		int num=0;
		if("1".equals(type)){ //
			LocalDate date = new LocalDate().minusDays(30);
			for(int i=0;i<90;i++){
				LocalDate tmp = date.plusDays(i);
				long len =OrderJedis.lremData(tmp.toString(), adcode);
				num+=len;
			}
			List<AdSchedule> list = OrderJedis.queryAdSchedules(adcode);
			for(AdSchedule schedule:list){
				OrderJedis.del(adcode+"_"+schedule.getExposuredate());
				OrderJedis.lremData(schedule.getExposuredate(), adcode);
			}
			OrderJedis.lremData("lossorders", adcode);
		}else if("2".equals(type)){
			if(OrderJedis.writeValue("lossorders", adcode)){
				num=1;
			}
		}
		return num;
	}

	

}
